/*
 * @lc app=leetcode.cn id=232 lang=cpp
 *
 * [232] 用栈实现队列
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>

using namespace std;
// @lc code=start
class MyQueue {
public:
    stack<int> s1,s2;
    MyQueue() {

    }
    
    void push(int x) {
        s1.push(x);
    }
    
    int pop() {
        while(s1.size() > 1) {
            int a = s1.top();
            s2.push(a);
            s1.pop();
        }
        int ret = s1.top();
        s1.pop();
        while(!s2.empty()) {
            int a = s2.top();
            s1.push(a);
            s2.pop();
        }
        return ret;
    }
    
    int peek() {
        while(s1.size() > 1) {
            int a = s1.top();
            s2.push(a);
            s1.pop();
        }
        int ret = s1.top();
        while(!s2.empty()) {
            int a = s2.top();
            s1.push(a);
            s2.pop();
        }
        return ret;
    }
    
    bool empty() {
        return s1.empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
// @lc code=end

